const path = require('path');
const { app, BrowserWindow, ipcMain, dialog } = require('electron');


require('./server/handle-update.js')

require('./server/on/index.js');


const createWindow = () => {
	const win = new BrowserWindow({
		width: 800,
		height: 600,
		webPreferences: {
			preload: path.join(__dirname, './server/preload.js')
		},
		show: false,
	});
	win.webContents.openDevTools();
	win.loadFile(path.join(__dirname, './view/index.html'));
	win.once('ready-to-show', () => {
		win.show();
		win.webContents.send('message', 'ready-to-show');
	});
	global.mainWin = win;
	setTimeout(() => {
		dialog.showMessageBox({
			type: 'info',
			title: '欢迎',
			message: '欢迎使用本软件。',
			buttons: ['确定', '取消']
		}).then(resp => {
			win.webContents.send('message', '666');
		}).catch(err => {
			win.webContents.send('message', '666');
		})
	}, 3000)
}

app.whenReady().then(createWindow);

app.on('window-all-closed', () => {
	if (process.platform != 'darwin') app.quit();
});
app.on('activate', () => {
	if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
